<template>
	<view>
		<!-- 自定义的搜索框组件 -->
		<!-- 并且添加了吸顶的效果 -->
		<view class="search-box"> 
			<my-search @click="gotoSearchHandler"></my-search>
		</view>
		<!-- 轮播图的区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item, i) in swiperList" :key="i">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		
		<!-- 导航栏区域 -->
		<view class="nav-list">
			<view class="nav-item"  v-for="(item, i) in navList" :key="i" @click="navClickHandler(item)">
				<image :src="item.image_src" class="nav-img"></image>
			</view>
		</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<view>用来占位的test</view>
		<!-- 楼层的区域 
		<view class="floor-list">
			<view class="floor-item" v-for="(item, i) in floorList" :key="i">
				<!-- 标题 
				<view class="floor-name">{{item.floor_title.name}}</view>
				<view class="floor-img-box">
					<!-- 左侧的大图片盒子 
					<view class="left-img-box">
						<image class="floor-title" :src="item.floor_title.image_src" ></image>
					</view>
					<!-- 右侧小图片的盒子
					<view class="right-img-box" v-for="(item2, index) in item.product_list" :key="index"
						v-if="index != 0">
						<image :src="item2.image_src" :style="{width: 200 + 'rpx'} " mode="widthFix"></image>
					</view>
				</view>
			</view>
		</view> -->
		
		
	</view>
</template>

<script>
	import badgeMax from '@/maxins/tabbar_badge.js'
	
	export default {
		mixins: [badgeMax],
		data() {
			return {
				// 轮播图的数据列表
				'swiperList': [],
				
				// 分类导航的数据列表
				'navList': [],
				
				// 首页中的楼层数据列表
				'floorList': []
			};
		},
		onLoad() {
			// 调用在main.js中自定义的挂载在uni上的对象showMessage，
			//以达到封装弹框的效果，方便以后的调用
			// uni.$showMessage("数据请求成功"); 
			this.getSwiperList();
			
			this.getNavList();
			
			this.getFloorList();
		},
		methods: {
			// async getSwiperList() {
			// 	const  {data : res } = await uni.$http.get('/api/public/v1/home/swiperdata')
			// 	if (res.meta.status !== 200) {
			// 		return uni.showToast({
			// 			title: "数据请求失败",
			// 			duration: "1500",
			// 			icon:'none'
			// 		})
			// 	}
				
			// 	// 请求成功则
			// 	this.swiperList = res;
			// }
	
			// 由于后端还在开发，所以暂时使用静态资源进行展示轮播图
			// 获取轮播图的数据
			getSwiperList() {
				this.swiperList = [
					{
						"image_src" : "../../static/swiperImage/1.png",
						"open_type" : "navigate",
						"goods_id" : 129,
						"navigator_id" : "/pages/goods_detail/main?goods_id=129"
					},
					{
						"image_src" : "../../static/swiperImage/2.png",
						"open_type" : "navigate",
						"goods_id" : 130,
						"navigator_id" : "/pages/goods_detail/main?goods_id=130"
					}
				]
			},
			// 获取导航栏的数据
			getNavList() {
				this.navList = [
					{
						"name": "分类",
						"image_src": "../../static/navigatorImage/category.png",
						"open_type": "switchTab",
						"navigator_url": "/pages/category/main"
					},
					{
						"name": "纸巾",
						"image_src": "../../static/navigatorImage/paper.png"
					},
					{
						"name": "纸巾",
						"image_src": "../../static/navigatorImage/paper.png"
					},
					{
						"name": "纸巾",
						"image_src": "../../static/navigatorImage/paper.png"
					}
					
				];
				// console.log(this.navList);
			},
			// 点击导航栏的页面跳转处理
			navClickHandler(item) {
				// console.log(item);
				// 根据点击的导航栏传递的参数来进行跳转到对应的页面
				if (item.name === "分类") {
					// 由于分类是一个TabBar的页面，所以要用switchTab来进行跳转页面
					uni.switchTab({
						url:'../Cate/Cate'
					})
				} else if (item.name === "纸巾") {
					uni.switchTab({
						url:'../Cart/Cart'
					})
				}
			},
			// 获取首页楼层的数据
			// async getFloorList() {
			// 	const {data : res } = await uni.$http.get('/api/public/v1/home/floordata')
			// 	// 如果后台返回的转态码成功，则
			// 	if (res.meta.data !== 200) return uni.$showMessage()
			// 	//失败，则
			// 	this.floorList = res.message
			// }
			getFloorList() {
				//制造的静态数据
				this.floorList = [
					{
						"floor_title": {
							"name": "湿纸巾",
							"image_src": "../../static/floorImage/zhuyao.png"
						},
						"product_list": [
							{
								"name": "主要产品一",
								"image_src": "../../static/floorImage/zhuyao.png",
								"image_width": "232",
								"open_type": "navigate",
								"navigator_url": "/pages/goods_list?query=产品1"
							},
							{
								"name": "主要产品一",
								"image_src": "../../static/floorImage/zhuyao.png",
								"image_width": "232",
								"open_type": "navigate",
								"navigator_url": "/pages/goods_list?query=产品1"
							},{
								"name": "主要产品一",
								"image_src": "../../static/floorImage/zhuyao.png",
								"image_width": "232",
								"open_type": "navigate",
								"navigator_url": "/pages/goods_list?query=产品1"
							},
							{
								"name": "主要产品一",
								"image_src": "../../static/floorImage/zhuyao.png",
								"image_width": "232",
								"open_type": "navigate",
								"navigator_url": "/pages/goods_list?query=产品1"
							},{
								"name": "主要产品一",
								"image_src": "../../static/floorImage/zhuyao.png",
								"image_width": "232",
								"open_type": "navigate",
								"navigator_url": "/pages/goods_list?query=产品1"
							}
						]
					},
					{
						"floor_title": {
							"name": "干纸巾测试",
							"image_src": "../../static/floorImage/second.png"
						},
						"product_list": [
							{
								"name": "主要产品2",
								"image_src": "../../static/floorImage/second.png",
								"image_width": "232",
								"open_type": "navigate",
								"navigator_url": "/pages/goods_list?query=产品2"
							},
							{
								"name": "主要产品一",
								"image_src": "../../static/floorImage/second.png",
								"image_width": "232",
								"open_type": "navigate",
								"navigator_url": "/pages/goods_list?query=产品2"
							},{
								"name": "主要产品一",
								"image_src": "../../static/floorImage/second.png",
								"image_width": "232",
								"open_type": "navigate",
								"navigator_url": "/pages/goods_list?query=产品2"
							},
							{
								"name": "主要产品一",
								"image_src": "../../static/floorImage/second.png",
								"image_width": "232",
								"open_type": "navigate",
								"navigator_url": "/pages/goods_list?query=产品2"
							},{
								"name": "主要产品一",
								"image_src": "../../static/floorImage/second.png",
								"image_width": "232",
								"open_type": "navigate",
								"navigator_url": "/pages/goods_list?query=产品2"
							}
						]
					}
				]
			},
			
			gotoSearchHandler() {
				uni.navigateTo({
					url: '/subpkg/search/search'
				})
			}
			
		}
		
	}
</script>

<style lang="scss">
swiper {
	height: 330rpx;
	.swiper-item,
	image {
		width: 100%;
		height: 100%;
	}
}
.nav-list {
	display: flex;
	justify-content: space-around;
	margin: 15px, 0;
	.nav-img {
		width: 128rpx;
		height: 140rpx;
	}
}

.floor-name {
	font-size: 40rpx;
}
.floor-title {
	width: 200rpx;
	height:250rpx;
	// margin: 25rpx 0;
}

.right-img-box {
	display: flex;
	flex-wrap: wrap;
}

.floor-img-box {
	display: flex;
}

// 设置为吸顶的效果
.search-box {
	position: sticky;
	//吸顶的位置
	top: 0;
	// 提高层级,防止被轮播图覆盖
	z-index: 999;
}
</style>